#ifndef _VERTEX_BUFFER_WRAPPER_H
#define _VERTEX_BUFFER_WRAPPER_H

#include "Engine.h"

namespace Graphics
{
	struct VertexBufferWrapper
	{
		unsigned int byteOffset;
		unsigned int stride;
		unsigned int streamNumber;
		LPDIRECT3DVERTEXBUFFER9 vertexBuffer;

		bool Init(VertexDataWrapper& aVertexData)
		{
			byteOffset = 0;
			stride = aVertexData.stride;
			streamNumber = 0;

			HRESULT hr = Engine::GetDevice()->CreateVertexBuffer(aVertexData.size,
				0, aVertexData.fvf,
				D3DPOOL_DEFAULT, &vertexBuffer, NULL);

			if(FAILED(hr))
			{
				DL_CHK_ASSERT(false, ExtendedString("Failed to initialize VertexBuffer. hr = ") << hr);
				return false;
			}

			void* pVertices;
			hr = vertexBuffer->Lock(0, aVertexData.size, (void**)&pVertices, 0);
			
			if(FAILED(hr))
			{
				DL_CHK_ASSERT(false, ExtendedString("Failed to aquire VertexBuffer lock. hr = ") << hr);
				return false;
			}
			memcpy(pVertices, aVertexData.vertexData, aVertexData.size);
			vertexBuffer->Unlock();

			return true;
		}
	};
}

#endif